import logging
from redis import StrictRedis
from datetime import timedelta


# 基础配置类
class Config(object):
    # 秘钥
    SECRET_KEY = "asdfasdfiaofjkafjlasigdoasdafoiwoef"
    #调试模式
    DEBUG=True
    #文件最大缓存时间
    SEND_FILE_MAX_AGE_DEFAULT = 24 * 3600
    #日志级别
    LEVEL = logging.DEBUG

    # mysql配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/news"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # redis配置
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = '6379'

    # session配置
    SESSION_TYPE = "redis"
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    SESSION_USE_SIGNER = True
    PERMANENT_SESSION_LIFETIME = timedelta(seconds=3600*12)

#开发配置类
class DevelopConfig(Config):
    pass

#线上配置类
class ProductConfig(Config):
    DEBUG = False
    LEVEL = logging.ERROR

# 测试配置类
class TestingConfig(Config):
    TESTING = False

#根据键对应配置类，用于初始化app的加载类对象
config_dict = {
    "develop":DevelopConfig,
    "product":ProductConfig,
    "testing":TestingConfig
}
